From d7fc36e0d49d5f3076a98d89b8e8ba267501c494 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 23 Aug 2022 19:27:59 +0300 Subject: [PATCH] Improve visualization for tool Point from circle and tangent. --- .../tools/dialogpointfromcircleandtangent.cpp | 108 +++++++++++++----- .../tools/dialogpointfromcircleandtangent.h | 2 + .../vtoolpointfromcircleandtangent.cpp | 5 +- .../line/vistoolpointfromcircleandtangent.cpp | 22 ++++ 4 files changed, 107 insertions(+), 30 deletions(-) diff --git a/src/libs/vtools/dialogs/tools/dialogpointfromcircleandtangent.cpp b/src/libs/vtools/dialogs/tools/dialogpointfromcircleandtangent.cpp index 677156b97..e0290b5eb 100644 --- a/src/libs/vtools/dialogs/tools/dialogpointfromcircleandtangent.cpp +++ b/src/libs/vtools/dialogs/tools/dialogpointfromcircleandtangent.cpp @@ -49,6 +49,8 @@ #include "../vmisc/vabstractapplication.h" #include "../vmisc/vcommonsettings.h" #include "ui_dialogpointfromcircleandtangent.h" +#include "../vwidgets/vabstractmainwindow.h" +#include "../vgeometry/vpointf.h" //--------------------------------------------------------------------------------------------------------------------- DialogPointFromCircleAndTangent::DialogPointFromCircleAndTangent(const VContainer *data, quint32 toolId, @@ -205,42 +207,90 @@ void DialogPointFromCircleAndTangent::SetCrossCirclesPoint(const CrossCirclesPoi } } +//--------------------------------------------------------------------------------------------------------------------- +void DialogPointFromCircleAndTangent::ShowDialog(bool click) +{ + if (not prepare) + { + return; + } + + auto FinishCreating = [this]() + { + vis->SetMode(Mode::Show); + vis->RefreshGeometry(); + + emit ToolTip(QString()); + + setModal(true); + show(); + }; + + if (click) + { + // The check need to ignore first release of mouse button. + // User can select point by clicking on a label. + if (not m_firstRelease) + { + m_firstRelease = true; + return; + } + + /*We will ignore click if pointer is in point circle*/ + auto *scene = qobject_cast(VAbstractValApplication::VApp()->getCurrentScene()); + SCASSERT(scene != nullptr) + const QSharedPointer center = data->GeometricObject(GetCircleCenterId()); + QLineF line = QLineF(static_cast(*center), scene->getScenePos()); + + SetCircleRadius(QString::number(FromPixel(line.length(), *data->GetPatternUnit()))); + + FinishCreating(); + } + + FinishCreating(); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogPointFromCircleAndTangent::ChosenObject(quint32 id, const SceneObject &type) { - if (prepare == false)// After first choose we ignore all objects + if (prepare)// After first choose we ignore all objects { - if (type == SceneObject::Point) - { - VisToolPointFromCircleAndTangent *point = qobject_cast(vis); - SCASSERT(point != nullptr) + return; + } - switch (number) - { - case 0: - if (SetObject(id, ui->comboBoxTangentPoint, tr("Select a circle center"))) + if (type == SceneObject::Point) + { + auto *point = qobject_cast(vis); + SCASSERT(point != nullptr) + + switch (number) + { + case 0: + if (SetObject(id, ui->comboBoxTangentPoint, tr("Select a circle center"))) + { + number++; + point->VisualMode(id); + } + break; + case 1: + if (getCurrentObjectId(ui->comboBoxTangentPoint) != id) + { + if (SetObject(id, ui->comboBoxCircleCenter, QString())) { - number++; - point->VisualMode(id); + auto *window = qobject_cast( + VAbstractValApplication::VApp()->getMainWindow()); + SCASSERT(window != nullptr) + connect(vis.data(), &Visualization::ToolTip, window, &VAbstractMainWindow::ShowToolTip); + + number = 0; + point->SetCenterId(id); + point->RefreshGeometry(); + prepare = true; } - break; - case 1: - if (getCurrentObjectId(ui->comboBoxTangentPoint) != id) - { - if (SetObject(id, ui->comboBoxCircleCenter, QString())) - { - number = 0; - point->SetCenterId(id); - point->RefreshGeometry(); - prepare = true; - this->setModal(true); - this->show(); - } - } - break; - default: - break; - } + } + break; + default: + break; } } } diff --git a/src/libs/vtools/dialogs/tools/dialogpointfromcircleandtangent.h b/src/libs/vtools/dialogs/tools/dialogpointfromcircleandtangent.h index 7cc5dfdb1..65966c36a 100644 --- a/src/libs/vtools/dialogs/tools/dialogpointfromcircleandtangent.h +++ b/src/libs/vtools/dialogs/tools/dialogpointfromcircleandtangent.h @@ -70,6 +70,7 @@ public: void SetNotes(const QString ¬es); QString GetNotes() const; + void ShowDialog(bool click) override; public slots: virtual void ChosenObject(quint32 id, const SceneObject &type) override; void PointChanged(); @@ -101,6 +102,7 @@ private: bool flagError; /** @brief number number of handled objects */ qint32 number{0}; + bool m_firstRelease{false}; }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.cpp index a3f6fb5ae..7c376134f 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.cpp @@ -328,9 +328,12 @@ void VToolPointFromCircleAndTangent::SetVisualization() auto *visual = qobject_cast(vis); SCASSERT(visual != nullptr) + const bool osSeparator = VAbstractApplication::VApp()->Settings()->GetOsSeparator(); + const VTranslateVars *trVars = VAbstractApplication::VApp()->TrVars(); + visual->SetPointId(tangentPointId); visual->SetCenterId(circleCenterId); - visual->SetCRadius(circleRadius); + visual->SetCRadius(trVars->FormulaToUser(circleRadius, osSeparator)); visual->SetCrossPoint(crossPoint); visual->RefreshGeometry(); } diff --git a/src/libs/vtools/visualization/line/vistoolpointfromcircleandtangent.cpp b/src/libs/vtools/visualization/line/vistoolpointfromcircleandtangent.cpp index 1badd385a..5f4774b3c 100644 --- a/src/libs/vtools/visualization/line/vistoolpointfromcircleandtangent.cpp +++ b/src/libs/vtools/visualization/line/vistoolpointfromcircleandtangent.cpp @@ -41,6 +41,7 @@ #include "../visualization.h" #include "visline.h" #include "../vwidgets/global.h" +#include "../vmisc/vmodifierkey.h" //--------------------------------------------------------------------------------------------------------------------- VisToolPointFromCircleAndTangent::VisToolPointFromCircleAndTangent(const VContainer *data, QGraphicsItem *parent) @@ -78,6 +79,27 @@ void VisToolPointFromCircleAndTangent::RefreshGeometry() m_cRadius, m_crossPoint, &fPoint); DrawPoint(m_point, fPoint, Color(VColor::MainColor)); } + else if (GetMode() == Mode::Creation) + { + QLineF cursorLine (static_cast(*center), ScenePos()); + qreal len = cursorLine.length(); + + m_cPath->setRect(PointRect(len)); + DrawPoint(m_cPath, static_cast(*center), Qt::darkGreen, Qt::DashLine); + + FindRays(static_cast(*tan), static_cast(*center), len); + + QPointF fPoint; + VToolPointFromCircleAndTangent::FindPoint(static_cast(*tan), static_cast(*center), + len, m_crossPoint, &fPoint); + DrawPoint(m_point, fPoint, Color(VColor::MainColor)); + + const QString prefix = UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true); + SetToolTip(tr("Radius = %1%2; " + "Mouse click - finish selecting the radius, " + "%3 - skip") + .arg(NumberToUser(len), prefix, VModifierKey::EnterKey())); + } } } }