From 990c03c69745529accabd61430fb41b1053e3267 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 25 Feb 2016 21:23:16 +0200 Subject: [PATCH] Updated dialog for the tool Spline. --HG-- branch : feature --- src/libs/vgeometry/vspline.cpp | 4 +- src/libs/vgeometry/vspline.h | 4 +- .../vtools/dialogs/tools/dialogspline.cpp | 351 ++++++- src/libs/vtools/dialogs/tools/dialogspline.h | 42 + src/libs/vtools/dialogs/tools/dialogspline.ui | 877 +++++++++++++++--- .../vtools/visualization/vistoolalongline.cpp | 2 +- src/libs/vtools/visualization/vistoolarc.cpp | 6 +- .../visualization/vistoolarcwithlength.cpp | 6 +- .../vtools/visualization/vistoolbisector.cpp | 2 +- .../vistoolcurveintersectaxis.cpp | 2 +- .../vtools/visualization/vistoolcutarc.cpp | 2 +- .../vtools/visualization/vistoolcutspline.cpp | 2 +- .../visualization/vistoolcutsplinepath.cpp | 2 +- .../vtools/visualization/vistoolendline.cpp | 4 +- .../vistoollineintersectaxis.cpp | 2 +- .../vtools/visualization/vistoolnormal.cpp | 2 +- .../vistoolpointfromcircleandtangent.cpp | 2 +- .../visualization/vistoolpointofcontact.cpp | 2 +- .../vistoolpointofintersectioncircles.cpp | 4 +- .../visualization/vistoolshoulderpoint.cpp | 2 +- .../vtools/visualization/visualization.cpp | 8 +- src/libs/vtools/visualization/visualization.h | 5 +- 22 files changed, 1131 insertions(+), 202 deletions(-) diff --git a/src/libs/vgeometry/vspline.cpp b/src/libs/vgeometry/vspline.cpp index 135926da9..d4fc3350c 100644 --- a/src/libs/vgeometry/vspline.cpp +++ b/src/libs/vgeometry/vspline.cpp @@ -768,13 +768,13 @@ qreal VSpline::GetC2Length() const } //--------------------------------------------------------------------------------------------------------------------- -QString VSpline::C1LengthFormula() const +QString VSpline::GetC1LengthFormula() const { return d->c1LengthF; } //--------------------------------------------------------------------------------------------------------------------- -QString VSpline::C2LengthFormula() const +QString VSpline::GetC2LengthFormula() const { return d->c2LengthF; } diff --git a/src/libs/vgeometry/vspline.h b/src/libs/vgeometry/vspline.h index 1e32d8422..410890c02 100644 --- a/src/libs/vgeometry/vspline.h +++ b/src/libs/vgeometry/vspline.h @@ -70,8 +70,8 @@ public: qreal GetC1Length() const; qreal GetC2Length() const; - QString C1LengthFormula() const; - QString C2LengthFormula() const; + QString GetC1LengthFormula() const; + QString GetC2LengthFormula() const; qreal GetLength () const; qreal GetKasm1() const; diff --git a/src/libs/vtools/dialogs/tools/dialogspline.cpp b/src/libs/vtools/dialogs/tools/dialogspline.cpp index 578bd12d5..bf0fb3e0c 100644 --- a/src/libs/vtools/dialogs/tools/dialogspline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogspline.cpp @@ -33,8 +33,10 @@ #include "../vgeometry/vspline.h" #include "../vpatterndb/vcontainer.h" #include "../../visualization/vistoolspline.h" +#include "../support/dialogeditwrongformula.h" #include +#include //--------------------------------------------------------------------------------------------------------------------- /** @@ -43,9 +45,42 @@ * @param parent parent widget */ DialogSpline::DialogSpline(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogSpline), spl(), newDuplicate(-1) + : DialogTool(data, toolId, parent), + ui(new Ui::DialogSpline), + spl(), + newDuplicate(-1), + formulaBaseHeightAngle1(0), + formulaBaseHeightAngle2(0), + formulaBaseHeightLength1(0), + formulaBaseHeightLength2(0), + timerAngle1(new QTimer(this)), + timerAngle2(new QTimer(this)), + timerLength1(new QTimer(this)), + timerLength2(new QTimer(this)), + flagAngle1(false), + flagAngle2(false), + flagLength1(false), + flagLength2(false) { ui->setupUi(this); + + plainTextEditFormula = ui->plainTextEditAngle1F; + + formulaBaseHeightAngle1 = ui->plainTextEditAngle1F->height(); + formulaBaseHeightAngle2 = ui->plainTextEditAngle2F->height(); + formulaBaseHeightLength1 = ui->plainTextEditLength1F->height(); + formulaBaseHeightLength2 = ui->plainTextEditLength2F->height(); + + ui->plainTextEditAngle1F->installEventFilter(this); + ui->plainTextEditAngle2F->installEventFilter(this); + ui->plainTextEditLength1F->installEventFilter(this); + ui->plainTextEditLength2F->installEventFilter(this); + + connect(timerAngle1, &QTimer::timeout, this, &DialogSpline::EvalAngle1); + connect(timerAngle2, &QTimer::timeout, this, &DialogSpline::EvalAngle2); + connect(timerLength1, &QTimer::timeout, this, &DialogSpline::EvalLength1); + connect(timerLength2, &QTimer::timeout, this, &DialogSpline::EvalLength2); + InitOkCancelApply(ui); FillComboBoxPoints(ui->comboBoxP1); @@ -59,6 +94,21 @@ DialogSpline::DialogSpline(const VContainer *data, const quint32 &toolId, QWidge connect(ui->comboBoxP4, static_cast(&QComboBox::currentIndexChanged), this, &DialogSpline::PointNameChanged); + connect(ui->toolButtonExprAngle1, &QPushButton::clicked, this, &DialogSpline::FXAngle1); + connect(ui->toolButtonExprAngle2, &QPushButton::clicked, this, &DialogSpline::FXAngle2); + connect(ui->toolButtonExprLength1, &QPushButton::clicked, this, &DialogSpline::FXLength1); + connect(ui->toolButtonExprLength2, &QPushButton::clicked, this, &DialogSpline::FXLength2); + + connect(ui->plainTextEditAngle1F, &QPlainTextEdit::textChanged, this, &DialogSpline::Angle1Changed); + connect(ui->plainTextEditAngle2F, &QPlainTextEdit::textChanged, this, &DialogSpline::Angle2Changed); + connect(ui->plainTextEditLength1F, &QPlainTextEdit::textChanged, this, &DialogSpline::Length1Changed); + connect(ui->plainTextEditLength2F, &QPlainTextEdit::textChanged, this, &DialogSpline::Length2Changed); + + connect(ui->pushButtonGrowAngle1, &QPushButton::clicked, this, &DialogSpline::DeployAngle1TextEdit); + connect(ui->pushButtonGrowAngle2, &QPushButton::clicked, this, &DialogSpline::DeployAngle2TextEdit); + connect(ui->pushButtonGrowLength1, &QPushButton::clicked, this, &DialogSpline::DeployLength1TextEdit); + connect(ui->pushButtonGrowLength2, &QPushButton::clicked, this, &DialogSpline::DeployLength2TextEdit); + vis = new VisToolSpline(data); auto path = qobject_cast(vis); SCASSERT(path != nullptr); @@ -125,14 +175,8 @@ void DialogSpline::ChosenObject(quint32 id, const SceneObject &type) //--------------------------------------------------------------------------------------------------------------------- void DialogSpline::SaveData() { - const qreal angle1 = ui->spinBoxAngle1->value(); - const qreal angle2 = ui->spinBoxAngle2->value(); - const qreal kAsm1 = ui->doubleSpinBoxKasm1->value(); - const qreal kAsm2 = ui->doubleSpinBoxKasm2->value(); - const qreal kCurve = ui->doubleSpinBoxKcurve->value(); - const quint32 d = spl.GetDuplicate();//Save previous value - spl = VSpline(*GetP1(), *GetP4(), angle1, angle2, kAsm1, kAsm2, kCurve); + spl = CurrentSpline(); newDuplicate <= -1 ? spl.SetDuplicate(d) : spl.SetDuplicate(static_cast(newDuplicate)); @@ -141,15 +185,173 @@ void DialogSpline::SaveData() path->setObject1Id(GetP1()->id()); path->setObject4Id(GetP4()->id()); - path->SetAngle1(angle1); - path->SetAngle2(angle2); - path->SetKAsm1(kAsm1); - path->SetKAsm2(kAsm2); - path->SetKCurve(kCurve); + path->SetAngle1(spl.GetStartAngle()); + path->SetAngle2(spl.GetEndAngle()); + path->SetKAsm1(spl.GetKasm1()); + path->SetKAsm2(spl.GetKasm2()); + path->SetKCurve(spl.GetKcurve()); path->SetMode(Mode::Show); path->RefreshGeometry(); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSpline::closeEvent(QCloseEvent *event) +{ + ui->plainTextEditAngle1F->blockSignals(true); + ui->plainTextEditAngle2F->blockSignals(true); + ui->plainTextEditLength1F->blockSignals(true); + ui->plainTextEditLength2F->blockSignals(true); + DialogTool::closeEvent(event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSpline::DeployAngle1TextEdit() +{ + DeployFormula(ui->plainTextEditAngle1F, ui->pushButtonGrowAngle1, formulaBaseHeightAngle1); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSpline::DeployAngle2TextEdit() +{ + DeployFormula(ui->plainTextEditAngle2F, ui->pushButtonGrowAngle2, formulaBaseHeightAngle2); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSpline::DeployLength1TextEdit() +{ + DeployFormula(ui->plainTextEditLength1F, ui->pushButtonGrowLength1, formulaBaseHeightLength1); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSpline::DeployLength2TextEdit() +{ + DeployFormula(ui->plainTextEditLength2F, ui->pushButtonGrowLength2, formulaBaseHeightLength2); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSpline::Angle1Changed() +{ + labelEditFormula = ui->labelEditAngle1; + labelResultCalculation = ui->labelResultAngle1; + ValFormulaChanged(flagAngle1, ui->plainTextEditAngle1F, timerAngle1); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSpline::Angle2Changed() +{ + labelEditFormula = ui->labelEditAngle2; + labelResultCalculation = ui->labelResultAngle2; + ValFormulaChanged(flagAngle2, ui->plainTextEditAngle2F, timerAngle2); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSpline::Length1Changed() +{ + labelEditFormula = ui->labelEditLength1; + labelResultCalculation = ui->labelResultLength1; + ValFormulaChanged(flagLength1, ui->plainTextEditLength1F, timerLength1); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSpline::Length2Changed() +{ + labelEditFormula = ui->labelEditLength2; + labelResultCalculation = ui->labelResultLength2; + ValFormulaChanged(flagLength2, ui->plainTextEditLength2F, timerLength2); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSpline::FXAngle1() +{ + auto dialog = new DialogEditWrongFormula(data, toolId, this); + dialog->setWindowTitle(tr("Edit first control point angle")); + QString angle1F = qApp->TrVars()->FormulaFromUser(ui->plainTextEditAngle1F->toPlainText(), + qApp->Settings()->GetOsSeparator()); + dialog->SetFormula(angle1F); + dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true)); + if (dialog->exec() == QDialog::Accepted) + { + angle1F = qApp->TrVars()->FormulaToUser(dialog->GetFormula()); + // increase height if needed. + if (angle1F.length() > 80) + { + DeployAngle1TextEdit(); + } + ui->plainTextEditAngle1F->setPlainText(angle1F); + MoveCursorToEnd(ui->plainTextEditAngle1F); + } + delete dialog; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSpline::FXAngle2() +{ + auto dialog = new DialogEditWrongFormula(data, toolId, this); + dialog->setWindowTitle(tr("Edit second control point angle")); + QString angle2F = qApp->TrVars()->FormulaFromUser(ui->plainTextEditAngle2F->toPlainText(), + qApp->Settings()->GetOsSeparator()); + dialog->SetFormula(angle2F); + dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true)); + if (dialog->exec() == QDialog::Accepted) + { + angle2F = qApp->TrVars()->FormulaToUser(dialog->GetFormula()); + // increase height if needed. + if (angle2F.length() > 80) + { + DeployAngle1TextEdit(); + } + ui->plainTextEditAngle2F->setPlainText(angle2F); + MoveCursorToEnd(ui->plainTextEditAngle2F); + } + delete dialog; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSpline::FXLength1() +{ + auto dialog = new DialogEditWrongFormula(data, toolId, this); + dialog->setWindowTitle(tr("Edit first control point length")); + QString length1F = qApp->TrVars()->FormulaFromUser(ui->plainTextEditLength1F->toPlainText(), + qApp->Settings()->GetOsSeparator()); + dialog->SetFormula(length1F); + dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true)); + if (dialog->exec() == QDialog::Accepted) + { + length1F = qApp->TrVars()->FormulaToUser(dialog->GetFormula()); + // increase height if needed. + if (length1F.length() > 80) + { + DeployLength1TextEdit(); + } + ui->plainTextEditLength1F->setPlainText(length1F); + MoveCursorToEnd(ui->plainTextEditLength1F); + } + delete dialog; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSpline::FXLength2() +{ + auto dialog = new DialogEditWrongFormula(data, toolId, this); + dialog->setWindowTitle(tr("Edit second control point length")); + QString length2F = qApp->TrVars()->FormulaFromUser(ui->plainTextEditLength2F->toPlainText(), + qApp->Settings()->GetOsSeparator()); + dialog->SetFormula(length2F); + dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true)); + if (dialog->exec() == QDialog::Accepted) + { + length2F = qApp->TrVars()->FormulaToUser(dialog->GetFormula()); + // increase height if needed. + if (length2F.length() > 80) + { + DeployLength2TextEdit(); + } + ui->plainTextEditLength2F->setPlainText(length2F); + MoveCursorToEnd(ui->plainTextEditLength2F); + } + delete dialog; +} + //--------------------------------------------------------------------------------------------------------------------- const QSharedPointer DialogSpline::GetP1() const { @@ -162,6 +364,91 @@ const QSharedPointer DialogSpline::GetP4() const return data->GeometricObject(getCurrentObjectId(ui->comboBoxP4)); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSpline::EvalAngle1() +{ + labelEditFormula = ui->labelEditAngle1; + Eval(ui->plainTextEditAngle1F->toPlainText(), flagAngle1, ui->labelResultAngle1, degreeSymbol, false); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSpline::EvalAngle2() +{ + labelEditFormula = ui->labelEditAngle2; + Eval(ui->plainTextEditAngle2F->toPlainText(), flagAngle2, ui->labelResultAngle2, degreeSymbol, false); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSpline::EvalLength1() +{ + labelEditFormula = ui->labelEditLength1; + const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit(), true); + const qreal length1 = Eval(ui->plainTextEditLength1F->toPlainText(), flagLength1, ui->labelResultLength1, postfix); + + if (length1 < 0) + { + flagLength1 = false; + ChangeColor(labelEditFormula, Qt::red); + ui->labelResultLength1->setText(tr("Error") + " (" + postfix + ")"); + ui->labelResultLength1->setToolTip(tr("Length can't be negative")); + + DialogSpline::CheckState(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSpline::EvalLength2() +{ + labelEditFormula = ui->labelEditLength2; + const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit(), true); + const qreal length2 = Eval(ui->plainTextEditLength2F->toPlainText(), flagLength2, ui->labelResultLength2, postfix); + + if (length2 < 0) + { + flagLength2 = false; + ChangeColor(labelEditFormula, Qt::red); + ui->labelResultLength2->setText(tr("Error") + " (" + postfix + ")"); + ui->labelResultLength2->setToolTip(tr("Length can't be negative")); + + DialogSpline::CheckState(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VSpline DialogSpline::CurrentSpline() const +{ + QString angle1F = ui->plainTextEditAngle1F->toPlainText(); + angle1F.replace("\n", " "); + + QString angle2F = ui->plainTextEditAngle2F->toPlainText(); + angle2F.replace("\n", " "); + + QString length1F = ui->plainTextEditLength1F->toPlainText(); + length1F.replace("\n", " "); + + QString length2F = ui->plainTextEditLength2F->toPlainText(); + length2F.replace("\n", " "); + + const QHash vars = data->PlainVariables(); + + const qreal angle1 = Visualization::FindVal(angle1F, vars); + const qreal angle2 = Visualization::FindVal(angle2F, vars); + const qreal length1 = Visualization::FindLength(length1F, vars); + const qreal length2 = Visualization::FindLength(length2F, vars); + + const bool separator = qApp->Settings()->GetOsSeparator(); + + angle1F = qApp->TrVars()->FormulaFromUser(angle1F, separator); + angle2F = qApp->TrVars()->FormulaFromUser(angle2F, separator); + length1F = qApp->TrVars()->FormulaFromUser(length1F, separator); + length2F = qApp->TrVars()->FormulaFromUser(length2F, separator); + + VSpline spline(*GetP1(), *GetP4(), angle1, angle1F, angle2, angle2F, length1, length1F, length2, length2F, + ui->doubleSpinBoxKcurve->value()); + + return spline; +} + //--------------------------------------------------------------------------------------------------------------------- void DialogSpline::PointNameChanged() { @@ -217,11 +504,13 @@ void DialogSpline::ShowDialog(bool click) spl = VSpline(*GetP1(), path->GetP2(), path->GetP3(), *GetP4(), ui->doubleSpinBoxKcurve->value()); - ui->spinBoxAngle1->setValue(static_cast(spl.GetStartAngle())); - ui->spinBoxAngle2->setValue(static_cast(spl.GetEndAngle())); + const QString angle1F = qApp->TrVars()->FormulaToUser(spl.GetStartAngleFormula()); + const QString angle2F = qApp->TrVars()->FormulaToUser(spl.GetEndAngleFormula()); - ui->doubleSpinBoxKasm1->setValue(spl.GetKasm1()); - ui->doubleSpinBoxKasm2->setValue(spl.GetKasm2()); + ui->plainTextEditAngle1F->setPlainText(angle1F); + ui->plainTextEditAngle2F->setPlainText(angle2F); + ui->plainTextEditLength1F->setPlainText(qApp->TrVars()->FormulaToUser(spl.GetC1LengthFormula())); + ui->plainTextEditLength2F->setPlainText(qApp->TrVars()->FormulaToUser(spl.GetC2LengthFormula())); if (not data->IsUnique(spl.name())) { @@ -234,6 +523,18 @@ void DialogSpline::ShowDialog(bool click) } } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSpline::CheckState() +{ + SCASSERT(bOk != nullptr); + bOk->setEnabled(flagAngle1 && flagAngle2 && flagLength1 && flagLength2 && flagError); + // In case dialog hasn't apply button + if ( bApply != nullptr) + { + bApply->setEnabled(bOk->isEnabled()); + } +} + //--------------------------------------------------------------------------------------------------------------------- void DialogSpline::ShowVisualization() { @@ -253,10 +554,18 @@ void DialogSpline::SetSpline(const VSpline &spline) setCurrentPointId(ui->comboBoxP1, spl.GetP1().id()); setCurrentPointId(ui->comboBoxP4, spl.GetP4().id()); - ui->spinBoxAngle1->setValue(static_cast(spl.GetStartAngle())); - ui->spinBoxAngle2->setValue(static_cast(spl.GetEndAngle())); - ui->doubleSpinBoxKasm1->setValue(spl.GetKasm1()); - ui->doubleSpinBoxKasm2->setValue(spl.GetKasm2()); + + const QString angle1F = qApp->TrVars()->FormulaToUser(spl.GetStartAngleFormula()); + const QString angle2F = qApp->TrVars()->FormulaToUser(spl.GetEndAngleFormula()); + + ui->plainTextEditAngle1F->setPlainText(angle1F); + ui->plainTextEditAngle2F->setPlainText(angle2F); + + const QString length1F = qApp->TrVars()->FormulaToUser(spl.GetC1LengthFormula()); + const QString length2F = qApp->TrVars()->FormulaToUser(spl.GetC2LengthFormula()); + + ui->plainTextEditLength1F->setPlainText(length1F); + ui->plainTextEditLength2F->setPlainText(length2F); ui->doubleSpinBoxKcurve->setValue(spl.GetKcurve()); ui->lineEditSplineName->setText(spl.name()); diff --git a/src/libs/vtools/dialogs/tools/dialogspline.h b/src/libs/vtools/dialogs/tools/dialogspline.h index ab7160b5b..d2cb64496 100644 --- a/src/libs/vtools/dialogs/tools/dialogspline.h +++ b/src/libs/vtools/dialogs/tools/dialogspline.h @@ -57,11 +57,28 @@ public slots: virtual void PointNameChanged() Q_DECL_OVERRIDE; virtual void ShowDialog(bool click) Q_DECL_OVERRIDE; protected: + virtual void CheckState() Q_DECL_OVERRIDE; virtual void ShowVisualization() Q_DECL_OVERRIDE; /** * @brief SaveData Put dialog data in local variables */ virtual void SaveData() Q_DECL_OVERRIDE; + virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE; +private slots: + void DeployAngle1TextEdit(); + void DeployAngle2TextEdit(); + void DeployLength1TextEdit(); + void DeployLength2TextEdit(); + + void Angle1Changed(); + void Angle2Changed(); + void Length1Changed(); + void Length2Changed(); + + void FXAngle1(); + void FXAngle2(); + void FXLength1(); + void FXLength2(); private: Q_DISABLE_COPY(DialogSpline) @@ -73,8 +90,33 @@ private: qint32 newDuplicate; + /** @brief formulaBaseHeight base height defined by dialogui */ + int formulaBaseHeightAngle1; + int formulaBaseHeightAngle2; + int formulaBaseHeightLength1; + int formulaBaseHeightLength2; + + /** @brief timerAngle1 timer of check first angle formula */ + QTimer *timerAngle1; + QTimer *timerAngle2; + QTimer *timerLength1; + QTimer *timerLength2; + + /** @brief flagAngle1 true if value of first angle is correct */ + bool flagAngle1; + bool flagAngle2; + bool flagLength1; + bool flagLength2; + const QSharedPointer GetP1() const; const QSharedPointer GetP4() const; + + void EvalAngle1(); + void EvalAngle2(); + void EvalLength1(); + void EvalLength2(); + + VSpline CurrentSpline() const; }; #endif // DIALOGSPLINE_H diff --git a/src/libs/vtools/dialogs/tools/dialogspline.ui b/src/libs/vtools/dialogs/tools/dialogspline.ui index 153cbefc1..4dc474346 100644 --- a/src/libs/vtools/dialogs/tools/dialogspline.ui +++ b/src/libs/vtools/dialogs/tools/dialogspline.ui @@ -6,8 +6,8 @@ 0 0 - 459 - 289 + 524 + 375 @@ -22,10 +22,7 @@ - - - 6 - + @@ -62,79 +59,368 @@ - - - - - - 0 - 0 - - - - 0.010000000000000 - - - 1.000000000000000 - - + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Length: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + Value + + + _ + + + + - - - - - 0 - 0 - - - - - 0 - 0 - - - - Angle: - - - true - - + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calulation + + + true + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + + + + + + 16 + 16 + + + + true + + + + - - - - - 0 - 0 - - - - 360 - - + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Angle: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + Value + + + _ + + + + - - - - - 0 - 0 - - - - - 0 - 0 - - - - Length ratio: - - - true - - + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calulation + + + true + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + + + + + + 16 + 16 + + + + true + + + + @@ -173,79 +459,368 @@ - - - - - - 0 - 0 - - - - - 0 - 0 - - - - Length ratio: - - - true - - + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Length: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + Value + + + _ + + + + - - - - - 0 - 0 - - - - 0.010000000000000 - - - 1.000000000000000 - - + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calulation + + + true + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + + + + + + 16 + 16 + + + + true + + + + - - - - - 0 - 0 - - - - - 0 - 0 - - - - Angle: - - - true - - + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Angle: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + Value + + + _ + + + + - - - - - 0 - 0 - - - - 360 - - + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calulation + + + true + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + + + + + + 16 + 16 + + + + true + + + + @@ -346,14 +921,16 @@ + buttonBox + label_2 + doubleSpinBoxKasm1 + + + comboBoxP1 - doubleSpinBoxKasm1 - spinBoxAngle1 comboBoxP4 - doubleSpinBoxKasm2 - spinBoxAngle2 doubleSpinBoxKcurve comboBoxColor buttonBox diff --git a/src/libs/vtools/visualization/vistoolalongline.cpp b/src/libs/vtools/visualization/vistoolalongline.cpp index 4d710b00b..3451cc265 100644 --- a/src/libs/vtools/visualization/vistoolalongline.cpp +++ b/src/libs/vtools/visualization/vistoolalongline.cpp @@ -57,7 +57,7 @@ void VisToolAlongLine::setObject2Id(const quint32 &value) //--------------------------------------------------------------------------------------------------------------------- void VisToolAlongLine::setLength(const QString &expression) { - length = FindLength(expression); + length = FindLength(expression, Visualization::data->PlainVariables()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/visualization/vistoolarc.cpp b/src/libs/vtools/visualization/vistoolarc.cpp index 6f93aeec8..7ac5e3f2c 100644 --- a/src/libs/vtools/visualization/vistoolarc.cpp +++ b/src/libs/vtools/visualization/vistoolarc.cpp @@ -61,17 +61,17 @@ void VisToolArc::RefreshGeometry() //--------------------------------------------------------------------------------------------------------------------- void VisToolArc::setRadius(const QString &expression) { - radius = FindLength(expression); + radius = FindLength(expression, Visualization::data->PlainVariables()); } //--------------------------------------------------------------------------------------------------------------------- void VisToolArc::setF1(const QString &expression) { - f1 = FindVal(expression); + f1 = FindVal(expression, Visualization::data->PlainVariables()); } //--------------------------------------------------------------------------------------------------------------------- void VisToolArc::setF2(const QString &expression) { - f2 = FindVal(expression); + f2 = FindVal(expression, Visualization::data->PlainVariables()); } diff --git a/src/libs/vtools/visualization/vistoolarcwithlength.cpp b/src/libs/vtools/visualization/vistoolarcwithlength.cpp index caeb445d4..c33c082b5 100644 --- a/src/libs/vtools/visualization/vistoolarcwithlength.cpp +++ b/src/libs/vtools/visualization/vistoolarcwithlength.cpp @@ -61,17 +61,17 @@ void VisToolArcWithLength::RefreshGeometry() //--------------------------------------------------------------------------------------------------------------------- void VisToolArcWithLength::setRadius(const QString &expression) { - radius = FindLength(expression); + radius = FindLength(expression, Visualization::data->PlainVariables()); } //--------------------------------------------------------------------------------------------------------------------- void VisToolArcWithLength::setF1(const QString &expression) { - f1 = FindVal(expression); + f1 = FindVal(expression, Visualization::data->PlainVariables()); } //--------------------------------------------------------------------------------------------------------------------- void VisToolArcWithLength::setLength(const QString &expression) { - length = FindLength(expression); + length = FindLength(expression, Visualization::data->PlainVariables()); } diff --git a/src/libs/vtools/visualization/vistoolbisector.cpp b/src/libs/vtools/visualization/vistoolbisector.cpp index be0d80e91..bb5ebf6b8 100644 --- a/src/libs/vtools/visualization/vistoolbisector.cpp +++ b/src/libs/vtools/visualization/vistoolbisector.cpp @@ -61,7 +61,7 @@ void VisToolBisector::setObject3Id(const quint32 &value) //--------------------------------------------------------------------------------------------------------------------- void VisToolBisector::setLength(const QString &expression) { - length = FindLength(expression); + length = FindLength(expression, Visualization::data->PlainVariables()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/visualization/vistoolcurveintersectaxis.cpp b/src/libs/vtools/visualization/vistoolcurveintersectaxis.cpp index db7a87bbc..af7a98363 100644 --- a/src/libs/vtools/visualization/vistoolcurveintersectaxis.cpp +++ b/src/libs/vtools/visualization/vistoolcurveintersectaxis.cpp @@ -94,7 +94,7 @@ QString VisToolCurveIntersectAxis::Angle() const //--------------------------------------------------------------------------------------------------------------------- void VisToolCurveIntersectAxis::SetAngle(const QString &expression) { - angle = FindVal(expression); + angle = FindVal(expression, Visualization::data->PlainVariables()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/visualization/vistoolcutarc.cpp b/src/libs/vtools/visualization/vistoolcutarc.cpp index 53c023dfe..9460b7914 100644 --- a/src/libs/vtools/visualization/vistoolcutarc.cpp +++ b/src/libs/vtools/visualization/vistoolcutarc.cpp @@ -72,5 +72,5 @@ void VisToolCutArc::RefreshGeometry() //--------------------------------------------------------------------------------------------------------------------- void VisToolCutArc::setLength(const QString &expression) { - length = FindLength(expression); + length = FindLength(expression, Visualization::data->PlainVariables()); } diff --git a/src/libs/vtools/visualization/vistoolcutspline.cpp b/src/libs/vtools/visualization/vistoolcutspline.cpp index a5ac3bb20..2af9d7836 100644 --- a/src/libs/vtools/visualization/vistoolcutspline.cpp +++ b/src/libs/vtools/visualization/vistoolcutspline.cpp @@ -72,5 +72,5 @@ void VisToolCutSpline::RefreshGeometry() //--------------------------------------------------------------------------------------------------------------------- void VisToolCutSpline::setLength(const QString &expression) { - length = FindLength(expression); + length = FindLength(expression, Visualization::data->PlainVariables()); } diff --git a/src/libs/vtools/visualization/vistoolcutsplinepath.cpp b/src/libs/vtools/visualization/vistoolcutsplinepath.cpp index 622c2927f..0402164cc 100644 --- a/src/libs/vtools/visualization/vistoolcutsplinepath.cpp +++ b/src/libs/vtools/visualization/vistoolcutsplinepath.cpp @@ -118,5 +118,5 @@ void VisToolCutSplinePath::RefreshGeometry() //--------------------------------------------------------------------------------------------------------------------- void VisToolCutSplinePath::setLength(const QString &expression) { - length = FindLength(expression); + length = FindLength(expression, Visualization::data->PlainVariables()); } diff --git a/src/libs/vtools/visualization/vistoolendline.cpp b/src/libs/vtools/visualization/vistoolendline.cpp index dcdde7a83..d7edbbc2c 100644 --- a/src/libs/vtools/visualization/vistoolendline.cpp +++ b/src/libs/vtools/visualization/vistoolendline.cpp @@ -74,11 +74,11 @@ QString VisToolEndLine::Angle() const //--------------------------------------------------------------------------------------------------------------------- void VisToolEndLine::SetAngle(const QString &expression) { - angle = FindVal(expression); + angle = FindVal(expression, Visualization::data->PlainVariables()); } //--------------------------------------------------------------------------------------------------------------------- void VisToolEndLine::setLength(const QString &expression) { - length = FindLength(expression); + length = FindLength(expression, Visualization::data->PlainVariables()); } diff --git a/src/libs/vtools/visualization/vistoollineintersectaxis.cpp b/src/libs/vtools/visualization/vistoollineintersectaxis.cpp index 3ba5ccc25..9cb606929 100644 --- a/src/libs/vtools/visualization/vistoollineintersectaxis.cpp +++ b/src/libs/vtools/visualization/vistoollineintersectaxis.cpp @@ -110,7 +110,7 @@ QString VisToolLineIntersectAxis::Angle() const //--------------------------------------------------------------------------------------------------------------------- void VisToolLineIntersectAxis::SetAngle(const QString &expression) { - angle = FindVal(expression); + angle = FindVal(expression, Visualization::data->PlainVariables()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/visualization/vistoolnormal.cpp b/src/libs/vtools/visualization/vistoolnormal.cpp index c5c29f8c1..b52227039 100644 --- a/src/libs/vtools/visualization/vistoolnormal.cpp +++ b/src/libs/vtools/visualization/vistoolnormal.cpp @@ -100,7 +100,7 @@ void VisToolNormal::setObject2Id(const quint32 &value) //--------------------------------------------------------------------------------------------------------------------- void VisToolNormal::setLength(const QString &expression) { - length = FindLength(expression); + length = FindLength(expression, Visualization::data->PlainVariables()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/visualization/vistoolpointfromcircleandtangent.cpp b/src/libs/vtools/visualization/vistoolpointfromcircleandtangent.cpp index 9a702d7bd..171223b1a 100644 --- a/src/libs/vtools/visualization/vistoolpointfromcircleandtangent.cpp +++ b/src/libs/vtools/visualization/vistoolpointfromcircleandtangent.cpp @@ -84,7 +84,7 @@ void VisToolPointFromCircleAndTangent::setObject2Id(const quint32 &value) //--------------------------------------------------------------------------------------------------------------------- void VisToolPointFromCircleAndTangent::setCRadius(const QString &value) { - cRadius = FindLength(value); + cRadius = FindLength(value, Visualization::data->PlainVariables()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/visualization/vistoolpointofcontact.cpp b/src/libs/vtools/visualization/vistoolpointofcontact.cpp index 6fb471c4f..2bac802c7 100644 --- a/src/libs/vtools/visualization/vistoolpointofcontact.cpp +++ b/src/libs/vtools/visualization/vistoolpointofcontact.cpp @@ -103,5 +103,5 @@ void VisToolPointOfContact::setRadiusId(const quint32 &value) //--------------------------------------------------------------------------------------------------------------------- void VisToolPointOfContact::setRadius(const QString &expression) { - radius = FindLength(expression); + radius = FindLength(expression, Visualization::data->PlainVariables()); } diff --git a/src/libs/vtools/visualization/vistoolpointofintersectioncircles.cpp b/src/libs/vtools/visualization/vistoolpointofintersectioncircles.cpp index 44cf2337a..74dbc45fb 100644 --- a/src/libs/vtools/visualization/vistoolpointofintersectioncircles.cpp +++ b/src/libs/vtools/visualization/vistoolpointofintersectioncircles.cpp @@ -102,13 +102,13 @@ void VisToolPointOfIntersectionCircles::setObject2Id(const quint32 &value) //--------------------------------------------------------------------------------------------------------------------- void VisToolPointOfIntersectionCircles::setC1Radius(const QString &value) { - c1Radius = FindLength(value); + c1Radius = FindLength(value, Visualization::data->PlainVariables()); } //--------------------------------------------------------------------------------------------------------------------- void VisToolPointOfIntersectionCircles::setC2Radius(const QString &value) { - c2Radius = FindLength(value); + c2Radius = FindLength(value, Visualization::data->PlainVariables()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/visualization/vistoolshoulderpoint.cpp b/src/libs/vtools/visualization/vistoolshoulderpoint.cpp index bdee934e3..24111f840 100644 --- a/src/libs/vtools/visualization/vistoolshoulderpoint.cpp +++ b/src/libs/vtools/visualization/vistoolshoulderpoint.cpp @@ -118,5 +118,5 @@ void VisToolShoulderPoint::setLineP2Id(const quint32 &value) //--------------------------------------------------------------------------------------------------------------------- void VisToolShoulderPoint::setLength(const QString &expression) { - length = FindLength(expression); + length = FindLength(expression, Visualization::data->PlainVariables()); } diff --git a/src/libs/vtools/visualization/visualization.cpp b/src/libs/vtools/visualization/visualization.cpp index a9f872d80..23c151801 100644 --- a/src/libs/vtools/visualization/visualization.cpp +++ b/src/libs/vtools/visualization/visualization.cpp @@ -135,13 +135,13 @@ QRectF Visualization::PointRect(const qreal &radius) const } //--------------------------------------------------------------------------------------------------------------------- -qreal Visualization::FindLength(const QString &expression) +qreal Visualization::FindLength(const QString &expression, const QHash &vars) { - return qApp->toPixel(FindVal(expression)); + return qApp->toPixel(FindVal(expression, vars)); } //--------------------------------------------------------------------------------------------------------------------- -qreal Visualization::FindVal(const QString &expression) +qreal Visualization::FindVal(const QString &expression, const QHash &vars) { qreal val = 0; if (expression.isEmpty()) @@ -157,7 +157,7 @@ qreal Visualization::FindVal(const QString &expression) formula.replace("\n", " "); formula = qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); Calculator *cal = new Calculator(); - val = cal->EvalFormula(data->PlainVariables(), formula); + val = cal->EvalFormula(vars, formula); delete cal; } catch (qmu::QmuParserError &e) diff --git a/src/libs/vtools/visualization/visualization.h b/src/libs/vtools/visualization/visualization.h index e2cff633c..03339f02e 100644 --- a/src/libs/vtools/visualization/visualization.h +++ b/src/libs/vtools/visualization/visualization.h @@ -58,6 +58,9 @@ public: Mode GetMode() const; void SetMode(const Mode &value); + + static qreal FindLength(const QString &expression, const QHash &vars); + static qreal FindVal(const QString &expression, const QHash &vars); signals: void ToolTip(const QString &toolTip); public slots: @@ -79,8 +82,6 @@ protected: QGraphicsEllipseItem *InitPoint(const QColor &color, QGraphicsItem *parent) const; QRectF PointRect(const qreal &radius) const; - qreal FindLength(const QString &expression); - qreal FindVal(const QString &expression); void DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color, Qt::PenStyle style = Qt::SolidLine); virtual void DrawLine(QGraphicsLineItem *lineItem, const QLineF &line, const QColor &color,