Improve visualization for tool Point from circle and tangent.

This commit is contained in:
Roman Telezhynskyi 2022-08-23 19:27:59 +03:00
parent c10279c7e1
commit d7fc36e0d4
4 changed files with 107 additions and 30 deletions

View File

@ -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<VMainGraphicsScene *>(VAbstractValApplication::VApp()->getCurrentScene());
SCASSERT(scene != nullptr)
const QSharedPointer<VPointF> center = data->GeometricObject<VPointF>(GetCircleCenterId());
QLineF line = QLineF(static_cast<QPointF>(*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<VisToolPointFromCircleAndTangent *>(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<VisToolPointFromCircleAndTangent *>(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<VAbstractMainWindow *>(
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;
}
}
}

View File

@ -70,6 +70,7 @@ public:
void SetNotes(const QString &notes);
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};
};
//---------------------------------------------------------------------------------------------------------------------

View File

@ -328,9 +328,12 @@ void VToolPointFromCircleAndTangent::SetVisualization()
auto *visual = qobject_cast<VisToolPointFromCircleAndTangent *>(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();
}

View File

@ -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<QPointF>(*center), ScenePos());
qreal len = cursorLine.length();
m_cPath->setRect(PointRect(len));
DrawPoint(m_cPath, static_cast<QPointF>(*center), Qt::darkGreen, Qt::DashLine);
FindRays(static_cast<QPointF>(*tan), static_cast<QPointF>(*center), len);
QPointF fPoint;
VToolPointFromCircleAndTangent::FindPoint(static_cast<QPointF>(*tan), static_cast<QPointF>(*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; "
"<b>Mouse click</b> - finish selecting the radius, "
"<b>%3</b> - skip")
.arg(NumberToUser(len), prefix, VModifierKey::EnterKey()));
}
}
}
}